package com.mxm.app.myapplication;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class Test1 extends AppCompatActivity {
    private Button but1;
    private TextView text_view1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.test1);
        but1 = findViewById(R.id.test_but1);
        text_view1 = findViewById(R.id.text_view1);
        but1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i = new Intent();
                i.putExtra("txt","子页面返回内容");
                setResult(0,i);//传输数据到主页面
            finish();//关闭当前窗口
            }
        });
        text_view1.setText(getIntent().getStringExtra("txt"));//获取主页面传输的数据并显示到当前窗口
    }
}
